from django.contrib import admin
from .models import AnhuiCampaign,AnhuiCampaignCtrl

# Register your models here.
def make_is_semi_to_zero(modeladmin, request, queryset):
    queryset.update(is_semi=0)
make_is_semi_to_zero.short_description = "批量将is_semi设置为0"

def make_is_semi_to_one(modeladmin, request, queryset):
    queryset.update(is_semi=1)
make_is_semi_to_one.short_description = "批量将is_semi设置为1"

def make_is_final_to_zero(modeladmin, request, queryset):
    queryset.update(is_final=0)
make_is_final_to_zero.short_description = "批量将is_final设置为0"

def make_is_final_to_one(modeladmin, request, queryset):
    queryset.update(is_final=1)
make_is_final_to_one.short_description = "批量将is_final设置为1"

def make_status_0_to_zero(modeladmin, request, queryset):
    queryset.update(status_0=0)
make_status_0_to_zero.short_description = "批量将status_0设置为0"

def make_status_0_to_one(modeladmin, request, queryset):
    queryset.update(status_0=1)
make_status_0_to_one.short_description = "批量将status_0设置为1"

def make_status_1_to_zero(modeladmin, request, queryset):
    queryset.update(status_1=0)
make_status_1_to_zero.short_description = "批量将status_1设置为0"

def make_status_1_to_one(modeladmin, request, queryset):
    queryset.update(status_1=1)
make_status_1_to_one.short_description = "批量将status_1设置为1"


class AnhuiCampaignAdmin(admin.ModelAdmin):
	icon = '<i class="material-icons">assignment</i>'
	list_display = ('id','student_name','student_no','college_name','group_no','mobile','is_semi','is_final','score_0','score_1','status_0','status_1')
	list_display_links = ('id','student_name','student_no')
	list_filter = ('status_0','status_1','is_semi','is_final','group_no')
	search_fields = ('id', 'student_name', 'student_no','college_name','group_no','mobile')
	actions = [
		make_is_semi_to_zero,make_is_semi_to_one,
		make_is_final_to_zero,make_is_final_to_one,
		make_status_0_to_zero,make_status_0_to_one,
		make_status_1_to_zero,make_status_1_to_one,
	]


class AnhuiCampaignCtrlAdmin(admin.ModelAdmin):
	icon = '<i class="material-icons">gavel</i>'
	list_display = ('id','status')
	radio_fields = {"status": admin.VERTICAL}
	readonly_fields = ('id',)

admin.site.register(AnhuiCampaign,AnhuiCampaignAdmin)
admin.site.register(AnhuiCampaignCtrl,AnhuiCampaignCtrlAdmin)
